package com.zoro.barn.business.service.system.business.systeminfo.service;

import com.zoro.barn.business.service.system.business.systeminfo.dao.BarnSystemInfoMapper;
import com.zoro.barn.business.service.system.business.systeminfo.entity.BarnSystemInfo;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import jakarta.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * @author zhaoxingwu
 */
@Service
public class BarnSystemInfoService {
    @Resource
    private BarnSystemInfoMapper barnSystemInfoMapper;


    /**
     * 保存
     *
     * @param data 数据
     * @return saved data
     */
    @Transactional(rollbackFor = Exception.class)
    public BarnSystemInfo save(BarnSystemInfo data) {
        if (StringUtils.isBlank(data.getPid())) {
            return null;
        }
        BarnSystemInfo old = this.barnSystemInfoMapper.getById(data.getPid());
        if (old == null) {
            // insert
            this.barnSystemInfoMapper.insert(data);
        } else {
            // update
            data.setUpdateTime(new Date());
            this.barnSystemInfoMapper.update(data);
        }
        return data;
    }

    /**
     * 条件查询
     *
     * @param param 查询条件
     * @return 查询结果
     */
    public List<BarnSystemInfo> query(BarnSystemInfo param) {
        return this.barnSystemInfoMapper.query(param);
    }

    /**
     * 主键查询
     *
     * @param pid pid
     * @return e
     */
    public BarnSystemInfo getById(String pid) {
        return this.barnSystemInfoMapper.getById(pid);
    }
}
